<template>
  <div id="my">
    <div class="user-info">
      <div class="wrapper">
        <div class="avater"><img :src="user.avatar?user.avatar:'https://img.lanrentuku.com/img/allimg/1206/5-120605204024.png'" /></div>
        <div class="name">{{user.username}}</div>
      </div>
      <div class="flex-wrapper">
        <div class="flex-item">
          <div class="number">0.00</div>
          <div class="text">账户余额</div>
        </div>
        <div class="flex-item">
          <div class="number">0.00</div>
          <div class="text">我的积分</div>
        </div>
        <div class="flex-item" @click="onClickOrder">
          <div class="number">{{user.order.length}}</div>
          <div class="text">我的订单</div>
        </div>
      </div>
    </div>

    <van-cell title="我的收藏" is-link to="/collect" />
    <van-cell title="我的足迹" is-link to="/footprint" />
    <van-cell title="地址管理" is-link to="/address" />
  </div>
</template>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
  #my{
    width: 100%;
    height: 100%;
    background-color: rgb(138, 136, 136);
    position: relative;
    margin-top: -10px;
    .user-info{
      box-sizing: border-box;
      width: calc(100% - 20px);
      margin: 10px;
      border-radius: 20px;
      background-color: honeydew;
      .wrapper{
        .avater{
          img{
            width: 50px;
            height: 50px;
            border-radius: 25px;
          }
          margin-top: 10px;
        }
        .name{
          font-size: 1.3rem;
          margin: 10px;
        }
      }
    }
    
  }

  .flex-wrapper{
    display: flex;
    width: 100%;
    flex-flow: row nowrap;
    margin-bottom: 20px;
    background-color: honeydew;
    border-radius: 20px;
    padding-top: 20px;
    padding-bottom: 20px;
    .flex-item{
      flex: 0 0 33%;
      width: 33%;
      text-align: center;
      .icon{
        font-size: 1.5rem;
      }
      .number{
        color: red;
      }
      .text{
        color: grey;
      }
    }
  }
  /deep/.van-cell__title{
    text-align: left;
  }
  
</style>

<script lang="ts">
// @ is an alias to /src
import { 
  Image as VanImage,Cell
} from 'vant';
import { Component, Prop, Vue, Watch, Model } from 'vue-property-decorator';
import router from '../router';
import store from '../store/index';
import orderApi from '../api/order.api';

Vue.use(VanImage).use(Cell);
@Component
export default class MyComponent extends Vue {
  private user: any={};
  
  async created(){
    store.commit('global/setShowPageLoading',true);
    await store.dispatch('user/getUser');
    this.user=store.getters['user/user'];

    store.commit('global/setShowPageLoading',false);
  }

  private onClickOrder(){
    router.push({
      path:'/orderList'
    })
  }
  
}
</script>
